package bme.andraskindler.treenventory.provider;

import java.util.Date;
import java.util.List;

import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import bme.andraskindler.treenventory.R;
import bme.andraskindler.treenventory.activity.DetailsActivity;
import bme.andraskindler.treenventory.model.TreeData;

/**
 * Szbványos ViewPagerAdapter, melyet a {@link DetailsActivity} használ.
 * @author andraskindler
 *
 */
public class DetailsPagerAdapter extends PagerAdapter {

	final List<TreeData> list;

	public DetailsPagerAdapter(final List<TreeData> data) {
		list = data;
	}

	@Override
	public Object instantiateItem(ViewGroup container, int position) {
		final View view = LayoutInflater.from(container.getContext()).inflate(R.layout.details_pager_item, container, false);

		final TreeData treedata = list.get(position);

		TextView.class.cast(view.findViewById(R.id.tv_details_date)).setText("Dátum: " + new Date(treedata.getDate()).toString());
		TextView.class.cast(view.findViewById(R.id.tv_details_type)).setText("Típus: " + treedata.getType());
		TextView.class.cast(view.findViewById(R.id.tv_details_diameter)).setText("Átmérő: " + treedata.getWidth());

		container.addView(view);
		return view;
	}
	
	public TreeData getItem(final int pos){
		return list.get(pos);
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == arg1;
	}

	@Override
	public void destroyItem(ViewGroup container, int position, Object object) {
		container.removeView(View.class.cast(object));
	}
}
